package com.group3.controller.adminController;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.group3.controller.Validated.Add;
import com.group3.controller.Validated.Select;
import com.group3.controller.Validated.Update;
import com.group3.domain.StudentInfo;
import com.group3.pojo.receive.KlassReceive;
import com.group3.pojo.receive.StudentReceive;
import com.group3.pojo.result.KlassResult;
import com.group3.service.impl.AClassServiceImpl;
import com.group3.utils.Result;
import com.group3.service.AClassService;
import com.group3.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * AClassController
 *
 * @author HY
 * 2021/06/05 15:19
 **/


//管理班级的接口
@Api(tags = "管理员接口")
@RestController
@RequestMapping(value = "/admin/class")
public class AClassController {

    @Resource
    private AClassService aClassService;

    //    管理员增加班级信息
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "departName", value = "院系",required = true,
//                    dataType = "String", paramType = "body"),
//            @ApiImplicitParam(name = "professionName", value = "专业",required = true,
//                    dataType = "String", paramType = "body"),
//            @ApiImplicitParam(name = "classId", value = "班级名",required = true,
//                    dataType = "String", paramType = "body"),
//            @ApiImplicitParam(name = "grade", value = "年级",required = true,
//                    dataType = "String", paramType = "body"),
//            @ApiImplicitParam(name = "position", value = "班主任工号",required = true,
//                    dataType = "String", paramType = "body"),
//            @ApiImplicitParam(name = "status", value = "班级是否结业",required = true,
//                    dataType = "String", paramType = "body"),
//    })

    @PostMapping(value = "")
    @ApiOperation(value = "增加班级信息")
    //TODO 打样：取消添加class时出现分页参数
    @ApiOperationSupport(ignoreParameters = {
            "pageSize",
            "pageNumber"})
    public Result addClass(
            @Validated({Add.class}) @RequestBody KlassReceive klassReceive){

//        return ResultUtil.success(klassReceive.toString());
        return aClassService.addClass(klassReceive);
    }

    //    管理员查询班级信息
    @GetMapping(value = "")
    @ApiOperation(value = "查询班级信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "classId", value = "班级名",
                    dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "departName", value = "院系",
                    dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "professionName", value = "专业",
                    dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "grade", value = "年级",
                    dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "班级是否结业",
                    dataType = "int", paramType = "query")
    })
    // 待测试
    public Result<List<KlassResult>> selectClass(
            @Validated(Select.class) @ApiIgnore KlassReceive klassReceive){

//        return ResultUtil.success(klassReceive.toString());
        return aClassService.selectClass(klassReceive);
    }

    //    管理员修改班级信息
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "classId", value = "班级名",
//                    dataType = "String"),
//            @ApiImplicitParam(name = "departName", value = "院系",
//                    dataType = "String"),
//            @ApiImplicitParam(name = "professionName", value = "专业",
//                    dataType = "String"),
//            @ApiImplicitParam(name = "grade", value = "年级",
//                    dataType = "String"),
//            @ApiImplicitParam(name = "teacherId", value = "教师工号",
//                    dataType = "String"),
//            @ApiImplicitParam(name = "status", value = "班级是否结业",
//                    dataType = "int"),
//    })
    @PutMapping(value = "")
    @ApiOperation(value = "修改班级信息")
    @ApiOperationSupport(ignoreParameters = {
//            "classId",
            "pageSize",
            "pageNumber"})
    public Result updateClass(
//            @NotEmpty @PathVariable("classId") String classId,
            @Validated({Update.class}) @RequestBody KlassReceive klassReceive){

//        return ResultUtil.success(klassReceive.toString());
        return aClassService.updateClass(klassReceive);
    }

    //    管理员查询班级内学生信息
    @GetMapping(value = "/students")
    @ApiOperation(value = "查询班级内学生信息")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "classId", value = "班级名",
//                    dataType = "String"),
//            @ApiImplicitParam(name = "studentName", value = "学生姓名",
//                    dataType = "String", paramType = "query"),
//            @ApiImplicitParam(name = "studentId", value = "学生学号",
//                    dataType = "String", paramType = "query"),
//            @ApiImplicitParam(name = "cardId", value = "学生身份证",
//                    dataType = "String", paramType = "query"),
//            @ApiImplicitParam(name = "sex", value = "学生性别",
//                    dataType = "int", paramType = "query"),
//            @ApiImplicitParam(name = "email", value = "学生邮箱",
//                    dataType = "String", paramType = "query"),
//            @ApiImplicitParam(name = "tel", value = "学生电话",
//                    dataType = "String", paramType = "query"),
//            @ApiImplicitParam(name = "type", value = "项目角色",
//                    dataType = "int", paramType = "query"),
//    })
    @ApiOperationSupport(ignoreParameters = {
            "pageSize",
            "pageNumber"})
    public Result<List<StudentInfo>> selectStudentByClass(
//            @NotEmpty @PathVariable("classId") String classId,
            @Validated(Select.class) StudentReceive studentReceive){

//        return ResultUtil.success(studentReceive.toString());
        return aClassService.selectStudentByClass(studentReceive);
    }

    //    管理员增加班级内学生信息
    @PostMapping(value = "/student")
    @ApiOperation(value = "增加班级内学生信息")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "classId", value = "班级名",required = true,
//                    dataType = "String"),
//            @ApiImplicitParam(name = "studentName", value = "学生姓名",required = true,
//                    dataType = "String"),
//            @ApiImplicitParam(name = "studentId", value = "学生学号",required = true,
//                    dataType = "String"),
//            @ApiImplicitParam(name = "sex", value = "学生性别",required = true,
//                    dataType = "int"),
//            @ApiImplicitParam(name = "cardId", value = "学生身份证",required = true,
//                    dataType = "String"),
//            @ApiImplicitParam(name = "email", value = "学生邮箱",required = true,
//                    dataType = "String"),
//            @ApiImplicitParam(name = "tel", value = "学生电话",required = true,
//                    dataType = "String"),
//            @ApiImplicitParam(name = "type", value = "项目角色",required = true,
//                    dataType = "int"),
//    })
    @ApiOperationSupport(ignoreParameters = {
            "pageSize",
            "pageNumber"})
    public Result addStudentByClass(
//            @NotEmpty @PathVariable("classId") String classId,
            @Validated(Add.class) @RequestBody StudentReceive studentReceive){

//        return ResultUtil.success(studentReceive.toString());
        return aClassService.addStudentByClass(studentReceive);
    }

//    //    管理员删除学生信息
//    @DeleteMapping(value = "")
//    @ApiOperation(value = "从班级中删除单个学生信息")
//    public Result deletStudent1(
//            @NotEmpty String studentId){
//
//        List<String> studentIds = new ArrayList<>();
//        studentIds.add(studentId);
//
//        return ResultUtil.success(studentIds.toString());
////        return aClassService.deletStudent(studentIds);
//    }

    //    管理员删除学生信息
    @DeleteMapping(value = "")
    @ApiOperation(value = "从班级中批量删除学生信息")
    public Result deletStudent(
            @NotEmpty @RequestBody List<String> studentIds){

//        return ResultUtil.success(studentIds.toString());
        return aClassService.deletStudent(studentIds);
    }

}
